
#include "HkpAabbPhantom.h"

namespace Havok
{
	namespace Dynamics
	{
		namespace Phantom
		{
			hkpAabbPhantom* getPhantom(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
			{
				hkAabb box = hkAabb(hkVector4(minX, minY, minZ), hkVector4(maxX, maxY, maxZ));
				return new hkpAabbPhantom(box);
			}

			HkpAabbPhantom::HkpAabbPhantom(BoundingBox^ aabb)
			{
				m_phantom = m_aabbPhantom = getPhantom(aabb->Min.X, aabb->Min.Y, aabb->Min.Z, aabb->Max.X, aabb->Max.Y, aabb->Max.Z);
			}

			array<Collision::HkpCollidable^>^ HkpAabbPhantom::GetOverlappingCollidables()
			{
				hkArray<hkpCollidable*>& collidables = m_aabbPhantom->getOverlappingCollidables();
				array<Collision::HkpCollidable^>^ outArray = gcnew array<Collision::HkpCollidable^>(collidables.getSize());

				for(int i = 0; i<collidables.getSize();i++)
				{
					outArray[i] = gcnew Collision::HkpCollidable(collidables[i]);
				}

				return outArray;
			}

			BoundingBox HkpAabbPhantom::Aabb::get()
			{
				const hkAabb& box= m_aabbPhantom->getAabb();
				return BoundingBox(
					Vector3(box.m_min.getSimdAt(0),box.m_min.getSimdAt(1),box.m_min.getSimdAt(2)),
					Vector3(box.m_max.getSimdAt(0),box.m_max.getSimdAt(1),box.m_max.getSimdAt(2)));
			}

			inline void setAabb(hkpAabbPhantom* m_phantom, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
			{
				m_phantom->setAabb(hkAabb(hkVector4(minX, minY, minZ), hkVector4(maxX,maxY, maxZ)));
			}

			void HkpAabbPhantom::Aabb::set(BoundingBox value)
			{
				setAabb(m_aabbPhantom, value.Min.X, value.Min.Y, value.Min.Z, value.Max.X, value.Max.Y, value.Max.Z);
			}
		}
	}
}